<?php

use yii\db\Migration;

class m170616_094623_create_meeting_tables extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        //1.创建会议
        $this->createTable('ts_meeting', [
            'id' => $this->primaryKey(),
            'author' => $this->string(64)->notNull()->comment('会议发起人'),
            'title' => $this->string(64)->notNull()->comment('会议名称'),
            'meeting_time' => $this->datetime()->comment('会议开始时间'),
            'addr' => $this->string()->comment('会议地址'),
            'content'=>$this->string()->comment('注意事项'),
            'create_at' => $this->datetime()->comment('添加时间'),
            ], $tableOptions);
        //2.会议参与人员表
        $this->createTable('ts_participant', [
            'id' => $this->primaryKey(),
            'meeting_id' => $this->Integer()->notNull()->comment('会议id'),
            'userid' => $this->string(64)->notNull()->comment('参会人员userid'),
            'status' => $this->smallInteger()->defaultValue(0)->comment('参会状态 1=确认 2=请假 3=签到'),
            'status_time' => $this->datetime()->comment('状态改变时间'),
            ], $tableOptions);
        $this->createIndex('meeting_id','ts_participant','meeting_id');
    }

    public function down()
    {
        $this->dropTable('ts_participant');
        $this->dropTable('ts_meeting');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
